package com.fuqiang.nightshopadmin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuqiang.nightshopadmin.mapper.IUmsResourceMapper;
import com.fuqiang.nightshopadmin.service.IUmsResourceService;
import com.fuqiang.nightshopumsmodel.entity.UmsResource;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 后台资源表 服务实现类
 * </p>
 *
 * @author fuqiang
 * @since 2020-04-14
 */
@Service
@AllArgsConstructor
public class UmsResourceServiceImpl extends ServiceImpl<IUmsResourceMapper, UmsResource> implements IUmsResourceService {

    private IUmsResourceMapper umsResourceMapper;

    @Override
    public List<UmsResource> listAll() {
        QueryWrapper<UmsResource> queryWrapper = new QueryWrapper<>();
        return umsResourceMapper.selectList(queryWrapper);
    }

    @Override
    public IPage<UmsResource> list(Long categoryId, String nameKeyword, String urlKeyword, Integer pageSize, Integer pageNum) {
        QueryWrapper<UmsResource> queryWrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(categoryId)){
            queryWrapper.lambda().like(UmsResource::getCategoryId,categoryId);
        }
        if(!StringUtils.isEmpty(nameKeyword)){
            queryWrapper.lambda().like(UmsResource::getName,nameKeyword);
        }
        if(!StringUtils.isEmpty(urlKeyword)){
            queryWrapper.lambda().like(UmsResource::getUrl,urlKeyword);
        }

        Page<UmsResource> page = new Page<>(pageNum,pageSize);
        IPage<UmsResource> umsAdminIPage = umsResourceMapper.selectPage(page, queryWrapper);
        return umsAdminIPage;
    }
}
